{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# import classy module\n",
    "from classy import Class"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create instance of the class \"Class\"\n",
    "LambdaCDM = Class()\n",
    "# pass input parameters\n",
    "LambdaCDM.set({'omega_b':0.0223828,'omega_cdm':0.1201075,'h':0.67810,'A_s':2.100549e-09,'n_s':0.9660499,'tau_reio':0.05430842})\n",
    "LambdaCDM.set({'output':'tCl,pCl,lCl,mPk','lensing':'yes','P_k_max_1/Mpc':3.0})\n",
    "# run class\n",
    "LambdaCDM.compute()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get all C_l output\n",
    "cls = LambdaCDM.lensed_cl(2500)\n",
    "# To check the format of cls\n",
    "cls.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ll = cls['ell'][2:]\n",
    "clTT = cls['tt'][2:]\n",
    "clEE = cls['ee'][2:]\n",
    "clPP = cls['pp'][2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# uncomment to get plots displayed in notebook\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "from math import pi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# plot C_l^TT\n",
    "plt.figure(1)\n",
    "plt.xscale('log');plt.yscale('linear');plt.xlim(2,2500)\n",
    "plt.xlabel(r'$\\ell$')\n",
    "plt.ylabel(r'$[\\ell(\\ell+1)/2\\pi]  C_\\ell^\\mathrm{TT}$')\n",
    "plt.plot(ll,clTT*ll*(ll+1)/2./pi,'r-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.savefig('warmup_cltt.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get P(k) at redhsift z=0\n",
    "import numpy as np\n",
    "kk = np.logspace(-4,np.log10(3),1000) # k in h/Mpc\n",
    "Pk = [] # P(k) in (Mpc/h)**3\n",
    "h = LambdaCDM.h() # get reduced Hubble for conversions to 1/Mpc\n",
    "for k in kk:\n",
    "    Pk.append(LambdaCDM.pk(k*h,0.)*h**3) # function .pk(k,z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# plot P(k)\n",
    "plt.figure(2)\n",
    "plt.xscale('log');plt.yscale('log');plt.xlim(kk[0],kk[-1])\n",
    "plt.xlabel(r'$k \\,\\,\\,\\, [h/\\mathrm{Mpc}]$')\n",
    "plt.ylabel(r'$P(k) \\,\\,\\,\\, [\\mathrm{Mpc}/h]^3$')\n",
    "plt.plot(kk,Pk,'b-')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.savefig('warmup_pk.pdf')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# optional: reset parameters to default in case you want \n",
    "# to set different parameters and rerun LambdaCDM.compute()\n",
    "LambdaCDM.empty()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
